# Date: 2013-12-30
Nginx_Install() {
tar -zxf nginx-$nginxVer.tar.gz
cd nginx-$nginxVer
./configure --user=www --group=www --prefix=/usr/local/nginx \
--sbin-path=/usr/local/nginx/sbin/nginx \
--conf-path=/usr/local/nginx/conf/nginx.conf \
--error-log-path=/usr/local/nginx/logs/error.log \
--http-log-path=/usr/local/nginx/logs/access.log \
--pid-path=/usr/local/nginx/logs/nginx.pid \
--lock-path=/usr/local/nginx/logs/nginx.lock \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-http_realip_module \
--with-pcre \
--http-client-body-temp-path=/usr/local/nginx/cache/client_body_temp \
--http-proxy-temp-path=/usr/local/nginx/cache/proxy_temp \
--http-fastcgi-temp-path=/usr/local/nginx/cache/fastcgi_temp \
--http-uwsgi-temp-path=/usr/local/nginx/cache/uwsgi_temp \
--http-scgi-temp-path=/usr/local/nginx/cache/scgi_temp \
--with-mail \
--with-mail_ssl_module
make && make install
mkdir /usr/local/nginx/cache && chown www.www /usr/local/nginx/cache
rm -f /usr/local/nginx/conf/nginx.conf
cp $CWD/conf/nginx.conf /usr/local/nginx/conf/
ln -s /usr/local/nginx/conf/nginx.conf /etc/nginx.conf
sed -i s/\$nginx_version/2013/g /usr/local/nginx/conf/fastcgi.conf
sed -i s/nginx/LNMP/g /usr/local/nginx/conf/fastcgi.conf

mkdir -p /var/www/localhost
cp $CWD/conf/nginx.vhost /usr/local/nginx/conf/vhost.conf.sample
cp $CWD/conf/nginx.vhost /var/www/localhost/.vhost
cp $CWD/conf/tz.php /var/www/localhost/
cp $CWD/conf/info.php /var/www/localhost/
cp $CWD/conf/index.php /var/www/localhost/
cp $CWD/conf/robots.txt /var/www/localhost/

if [ "$linux_type" = "rhel" ] ; then
   cp $CWD/conf/nginx.init /etc/init.d/nginx   
   chkconfig --add nginx >/dev/null 2>&1 && chkconfig --level 2345 nginx on
   [ "$?" != "0" ] && echo "/etc/init.d/nginx start" >> /etc/rc.local
else
   cp $CWD/conf/nginx-init_for-all.sh /etc/init.d/nginx
   sed -i '/exit 0/i\/etc/init.d/nginx start' /etc/rc.local
fi
chmod +x /etc/init.d/nginx
/etc/init.d/nginx start

}